package main

import (
	"flag"
	"fmt"
	"iot-base/common/config"

	"iot-base/common/notify"
	"iot-base/common/propertytype"
	"iot-base/pm/self/pickers"
	"os"
	"sync"
	"time"
)

var nodeID = flag.String("nodeId", "", "string类型参数 节点id 不填为当前节点id")
var devID = flag.String("devId", "", "string类型参数 设备id 不填为当前节点id")
var meteID = flag.String("meteId", "", "string类型参数 量id")
var subID = flag.String("subId", "", "string类型参数 子量id")
var index = flag.Int("index", 0, "string类型参数 量索引")
var value = flag.String("value", "", "string类型参数 值")
var reportTime = flag.Int64("rt", 0, "string类型参数 上报时间 不填为当前时间")

func main() {
	if len(os.Args) >= 2 {
		flag.Parse()
		if meteID == nil || *meteID == "" {
			fmt.Println("meteId 不能为空")
			return
		}
		if value == nil || *value == "" {
			fmt.Println("value 不能为空")
			return
		}
		if nodeID == nil {
			nodeID = &config.SelfOption.ID
		}
		if devID == nil {
			devID = &config.SelfOption.ID
		}
		var now = time.Now().Unix()
		if reportTime == nil || *reportTime == 0 {
			reportTime = &now
		}
		fmt.Println("reporttime is", reportTime)
		pRData := new(propertytype.Value)
		pRData.TID = *devID
		pRData.PID = *meteID
		pRData.SubID = *subID
		pRData.Mindex = *index
		pRData.ReportTime = *reportTime
		pRData.PickTime = *reportTime
		pRData.Value = *value
		//realdata.PSDataReady(pRData, nil)
		notify.RawDataEx(pRData)

		return
	}
	var wg sync.WaitGroup
	pickers.InitSelfPicker(&wg)
	fmt.Println("hello ----------------ps------------MIX-----------")
	wg.Wait()
}
